﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;
using TV_Organizer.Properties;

namespace TV_Organizer.FileScanner
{
    public static class Constants
    {
        static Constants()
        {
            var l_sourceRegexes = new Collection<NamedRegex>();
            foreach (var source in Settings.Default.Sources)
                l_sourceRegexes.Add(new NamedRegex(source, source, RegexOptions.IgnoreCase));
            Constants.SourceRegexes = l_sourceRegexes;

            var l_teamRegexes = new Collection<NamedRegex>();
            foreach (var team in Settings.Default.Teams)
                l_teamRegexes.Add(new NamedRegex(team, team, RegexOptions.IgnoreCase));
            Constants.TeamRegexes = l_teamRegexes;

            var l_formatRegexes = new Collection<NamedRegex>();
            foreach (var format in Settings.Default.Formats)
                l_formatRegexes.Add(new NamedRegex(format, format, RegexOptions.IgnoreCase));
            Constants.FormatRegexes = l_formatRegexes;

            var l_codecRegexes = new Collection<NamedRegex>();
            foreach (var codec in Settings.Default.Codecs)
                l_codecRegexes.Add(new NamedRegex(codec, codec, RegexOptions.IgnoreCase));
            Constants.CodecRegexes = l_codecRegexes;
        }

        public static IEnumerable<Regex> SesonEpisodeRegexes = new Collection<Regex>
        {
            new Regex("S([0-9]{1,2})E([0-9]{2,3})", RegexOptions.IgnoreCase),
            new Regex("([0-9]{1,2})x([0-9]{2,3})", RegexOptions.IgnoreCase),
            new Regex("([0-9]{1,2})([0-9]{2})", RegexOptions.IgnoreCase),
        };

        //private static IEnumerable<TVShowRegex> m_showsNamesRegex;
        //public static IEnumerable<TVShowRegex> ShowsNamesRegexes
        //{
        //    get
        //    {
        //        if (m_showsNamesRegex == null)
        //            m_showsNamesRegex = TVShow.TVShows.Select(s => new TVShowRegex(s)).ToList();
        //        return m_showsNamesRegex;
        //    }
        //}

        public static char[] CleanupCharacters = new char[] { '.', '-', '_', '\'', '"', '!', '*', '?', '(', ')', ' ' };
        public const char CleanupCharactersReplacement = ' ';

        public static IEnumerable<NamedRegex> TeamRegexes { get; private set; }
        public static IEnumerable<NamedRegex> SourceRegexes { get; private set; }
        public static IEnumerable<NamedRegex> FormatRegexes { get; private set; }
        public static IEnumerable<NamedRegex> CodecRegexes { get; private set; }

        private static readonly NamedRegex m_isSampleRegex = new NamedRegex("sample", "sample", RegexOptions.IgnoreCase);
        public static NamedRegex IsSampleRegex
        {
            get { return m_isSampleRegex; }
        }

        private static readonly NamedRegex m_isRealRegex = new NamedRegex("REAL", "REAL", RegexOptions.IgnoreCase);
        public static NamedRegex IsRealRegex
        {
            get { return m_isRealRegex; }
        }

        private static readonly NamedRegex m_isProperRegex = new NamedRegex("PROPER", "PROPER", RegexOptions.IgnoreCase);
        public static NamedRegex IsProperRegex
        {
            get { return m_isProperRegex; }
        }

        private static readonly NamedRegex m_isRepackRegex = new NamedRegex("REPACK", "REPACK", RegexOptions.IgnoreCase);
        public static NamedRegex IsRepackRegex
        {
            get { return m_isRepackRegex; }
        }

        private static readonly NamedRegex m_isReripRegex = new NamedRegex("RERiP", "RERiP", RegexOptions.IgnoreCase);
        public static NamedRegex IsReripRegex
        {
            get { return m_isReripRegex; }
        }

        private static readonly NamedRegex m_isInternalRegex = new NamedRegex("iNTERNAL", "iNTERNAL", RegexOptions.IgnoreCase);
        public static NamedRegex IsInternalRegex
        {
            get { return m_isInternalRegex; }
        }
    }
}
